<?php
	// Lấy thông tin từ bảng đặt hàng
	$dathang = new dathangbs();
	$dathang->MaNguoiDung = $_SESSION['MaNguoiDung'];
	$danhsach = $dathang->GetList();
?>
<h3>Lịch sử mua hàng</h3>
<?php 
	$stt = 1;
	
	for($i = 0; $i < count($danhsach); $i++)
	{
		echo "<h4>[{$stt}] {$danhsach[$i]['NgayDatHang']}. Nơi giao: {$danhsach[$i]['DiaChiGiaoHang']}. ĐT: {$danhsach[$i]['DienThoai']}</h4>";
		$dathang_ct = new dathangchitietbs();
		$dathang_ct->MaDatHang = $danhsach[$i]['MaDatHang'];
		$danhsach_chitiet = $dathang_ct->GetList();
		
		echo "<table class='List'>";
			echo "<tr>";
				echo "<th>STT</th>";
				echo "<th>Tên sản phẩm</th>";
				echo "<th>Đơn giá</th>";
				echo "<th>Số lượng mua</th>";
				echo "<th>Thành tiền</th>";
			echo "</tr>";
		
			$sttct = 1;
			for($j = 0; $j < count($danhsach_chitiet); $j++)
			{
				$sanpham = new sanphambs();
				$sanpham->MaSanPham = $danhsach_chitiet[$j]['MaSanPham'];
				$danhsach_sanpham = $sanpham->GetList();
				echo "<tr>";
					echo "<td>{$sttct}</td>";
					echo "<td>{$danhsach_sanpham[0]['TenSanPham']}</td>";
					echo "<td align='right'>" . number_format($danhsach_sanpham[0]['DonGia']) . "</td>";
					echo "<td align='right'>" . $danhsach_chitiet[$j]['SoLuong'] . "</td>";
					echo "<td align='right'>" . number_format($danhsach_sanpham[0]['DonGia'] * $danhsach_chitiet[$j]['SoLuong']). "</td>";
				echo "</tr>";
				
				$sttct++;
			}
			
		echo "</table>";
		
		$stt++;
	}
?>